﻿@model PaginationModel


<div class="pagenumber">
  @{
      const int pageIncrement = 2;
      const int pageTrailing = 5;
      var totalPageCount = Model.TotalPages;
      if (totalPageCount > 1)
      {

        var pageIndex = Model.CurrentPageIndex;
        var pageRangeStart = pageIndex <= pageIncrement ? 1 : pageIndex - pageIncrement;
        var pageRangeEnd = pageIndex + pageIncrement <= totalPageCount ? (totalPageCount > pageTrailing && pageIndex + pageIncrement < pageTrailing ? pageTrailing : pageIndex + pageIncrement) : totalPageCount;
        var preIndex= pageIndex>1? pageIndex-1:1;
        var nextIndex= pageIndex < totalPageCount ? pageIndex+1: totalPageCount;

      <a class="on" href="@($"{Model.Url}?pageindex=1{Model.Query}")">首页</a>
      <a class="on" href="@($"{Model.Url}?pageindex={preIndex}{Model.Query}")">上一页</a>
        for (var i = pageRangeStart; i <= pageRangeEnd; i++)
        {
          var active = pageIndex == i ? "now" : "on";
          <a class="@active" href="@($"{Model.Url}?pageindex={i}{Model.Query}")">@i</a>
        }
        <a class="on" href="@($"{Model.Url}?pageindex={nextIndex}{Model.Query}")">下一页</a>
      <a class="on" href="@($"{Model.Url}?pageindex={totalPageCount}{Model.Query}")">末页</a>
    }
  }
</div>